import { createApp } from "vue";
import pinia from "./stores";
import ElementPlus from "element-plus";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import "element-plus/dist/index.css";
import App from "./App.vue";
import router from "./router";
import "./styles/index.scss";
import ElSvg from "./components/SvgIcon/ElSvg";
import "./permission";

// 测试接口&代理配置是否成功
/* import { requestLogin } from "@/api/user";
requestLogin({ username: "admin", password: "111111" }); */

import Cartgory from "@/components/Cartgory/index.vue";
import { useUserInfoStore } from "./stores/userInfo";

const app = createApp(App);

const userInfoStore = useUserInfoStore(pinia);
app.directive("has", (el, binding) => {
  // 在用户按钮权限中判断该按钮的权限是否存在(存在就正常渲染，不存在就删除 DOM)
  if (!userInfoStore.userInfo.buttons.includes(binding.value)) {
    // 删除元素
    el.remove();
  }
});

ElSvg(app);

app.component("Cartgory", Cartgory);

app
  .use(pinia)
  .use(router)
  .use(ElementPlus, {
    locale: zhCn,
  })
  .mount("#app");
